package cn.tedu.kit;

import java.sql.*;

/**
 * @author :Colin
 * @version 创建时间: 2021/7/5 19:41
 */
public class JDBCUtils2 {
    public static void close(ResultSet rs, PreparedStatement ps,Connection conn){
        if(rs!=null){
            try {
                rs.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if(ps!=null){
            try {
                ps.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if(conn!=null){
            try {
                conn.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
    }

    public static Connection getConnection() throws Exception {
        //1.注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.连接数据库
        String url="jdbc:mysql://localhost:3306/colinbase";
        Connection conn = DriverManager.getConnection(url, "root", "root");
        return conn;
    }
}
